<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/User.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<script runat="server">

    


    protected void btnInsert_Click1(object sender, EventArgs e)
    {
        LOData.InsertParameters[0].DefaultValue = (GridView2.FooterRow.FindControl("TextBox1") as TextBox).Text;
        LOData.InsertParameters[1].DefaultValue = (GridView2.FooterRow.FindControl("TextBox1") as TextBox).Text;
        LOData.InsertParameters[2].DefaultValue = "1";
 
    }






    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {


    }



    protected void LinkButton9_Click(object sender, EventArgs e)
    {
        SqlDataSource1.InsertParameters[0].DefaultValue = (Panel1.FindControl("dl3") as DropDownList).Text;
        SqlDataSource1.InsertParameters[1].DefaultValue = (Panel1.FindControl("TextBox8") as TextBox).Text;
        SqlDataSource1.InsertParameters[2].DefaultValue = (Panel1.FindControl("dl4") as DropDownList).Text;
        SqlDataSource1.InsertParameters[3].DefaultValue = (Panel1.FindControl("TextBox9") as TextBox).Text;
        SqlDataSource1.InsertParameters[4].DefaultValue = (Panel1.FindControl("TextBox10") as TextBox).Text;
        SqlDataSource1.InsertParameters[5].DefaultValue = (Panel1.FindControl("TextBox11") as TextBox).Text;
        SqlDataSource1.InsertParameters[6].DefaultValue = "1";

        SqlDataSource1.Insert();
        Panel1.Visible = false;
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //InsertBtn.Visible = false;   
        Panel1.Visible = true;
    }

    protected void LinkButton10_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        //InsertBtn.Visible = true;
    }



    protected void DataList1_EditCommand1(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = e.Item.ItemIndex;
        DataList1.DataBind();
    }


    protected void DataList1_UpdateCommand1(object source, DataListCommandEventArgs e)
    {
        //SqlDataSource1.UpdateParameters[0].DefaultValue = (e.Item.FindControl("DropDownList1") as DropDownList).Text;
        SqlDataSource1.UpdateParameters[0].DefaultValue = (e.Item.FindControl("TextBox12") as TextBox).Text;
        SqlDataSource1.UpdateParameters[1].DefaultValue = (e.Item.FindControl("DropDownList2") as DropDownList).Text;
        SqlDataSource1.UpdateParameters[2].DefaultValue = (e.Item.FindControl("TextBox13") as TextBox).Text;
        SqlDataSource1.UpdateParameters[3].DefaultValue = (e.Item.FindControl("TextBox14") as TextBox).Text;
        SqlDataSource1.UpdateParameters[4].DefaultValue = (e.Item.FindControl("TextBox15") as TextBox).Text;
        SqlDataSource1.UpdateParameters[5].DefaultValue = (e.Item.FindControl("IDLabel") as Label).Text;

        SqlDataSource1.Update();

        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
 
    }

    protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    {
   
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
    }

    protected void DataList1_DeleteCommand1(object source, DataListCommandEventArgs e)
    {
        SqlDataSource1.DeleteParameters[0].DefaultValue = (e.Item.FindControl("IDLabel") as Label).Text;
        SqlDataSource1.Delete();
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ManageProgramDetail
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h1>ManageProgramDetail</h1>
    <cc1:TabContainer ID="programTab" runat="server" ActiveTabIndex="1" 
        Width="1083px" Height="600px">
        <cc1:TabPanel runat="server" HeaderText="Major" ID="tabMajor">
            <HeaderTemplate>Major</HeaderTemplate>
            <ContentTemplate>
                <br />
                <asp:DataList ID="DataList1" runat="server" CellPadding="4" DataKeyField="ID" 
                    DataSourceID="SqlDataSource1" ForeColor="#333333" 
                    oncancelcommand="DataList1_CancelCommand" 
                    oneditcommand="DataList1_EditCommand1" 
                    onupdatecommand="DataList1_UpdateCommand1" 
                    ondeletecommand="DataList1_DeleteCommand1">
                    <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
                    <EditItemTemplate>
                        <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' 
                            Visible="False" />
                        <br />
                        <asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' 
                            Visible="False" />
                        <table style="width:100%;">
                            <tr>
                                <td style="width: 402px">
                                    Name:
                                    <asp:TextBox ID="TextBox12" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
                                    <br />
                                    HeadOfMajor:
                                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="a2" 
                                        DataTextField="Name" DataValueField="ID" 
                                        SelectedValue='<%# Eval("HeadOfMajor") %>'>
                                    </asp:DropDownList>
                                    <asp:SqlDataSource ID="a2" runat="server" 
                                        ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString %>" 
                                        SelectCommand="SELECT [ID], [Name] FROM [Professor]"></asp:SqlDataSource>
                                    <br />
                                </td>
                                <td>
                                    Description:<asp:TextBox ID="TextBox13" runat="server" 
                                        Text='<%# Eval("Description") %>'></asp:TextBox>
                                    &nbsp;<br />
                                    Objective:
                                    <asp:TextBox ID="TextBox14" runat="server" Text='<%# Eval("Objective") %>'></asp:TextBox>
                                    <br />
                                    MajorLO:
                                    <asp:TextBox ID="TextBox15" runat="server" Text='<%# Eval("MajorLO") %>'></asp:TextBox>
                                </td>
                            </tr>
                        </table>
                        <asp:LinkButton ID="LinkButton14" runat="server" CommandName="Update">Update</asp:LinkButton>
                        &nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton15" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                        <br />
                    </EditItemTemplate>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <ItemTemplate>
                        <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' 
                            Visible="False" />
                        <br />
                        <asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' 
                            Visible="False" />
                        <table style="width:100%;">
                            <tr>
                                <td style="width: 402px">
                                    Name:
                                    <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                                    <br />
                                    HeadOfMajor:
                                    <asp:Label ID="HeadOfMajorLabel" runat="server" 
                                        Text='<%# Eval("ProfName") %>' />
                                    <br />
                                </td>
                                <td>
                                    Description:
                                    <asp:Label ID="DescriptionLabel" runat="server" 
                                        Text='<%# Eval("Description") %>' />
                                    <br />
                                    Objective:
                                    <asp:Label ID="ObjectiveLabel" runat="server" Text='<%# Eval("Objective") %>' />
                                    <br />
                                    MajorLO:
                                    <asp:Label ID="MajorLOLabel" runat="server" Text='<%# Eval("MajorLO") %>' />
                                </td>
                            </tr>
                        </table>
                        <br />
                        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton13" runat="server" CommandName="Detail" 
                            PostBackUrl='<%# Bind("ID", "/Home/Major/?id={0}") %>'>Detail</asp:LinkButton>
                        <br />
                    </ItemTemplate>
                    <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:DataList>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString %>" 
                    DeleteCommand="UPDATE [Major] SET [Status] = 0 WHERE [ID] = @ID" 
                    InsertCommand="INSERT INTO [Major] ([ProgramID], [Name], [HeadOfMajor], [Description], [Objective], [MajorLO], [Status]) VALUES (@ProgramID, @Name, @HeadOfMajor, @Description, @Objective, @MajorLO, @Status)" 
                    SelectCommand="SELECT Major.ID, Major.ProgramID, Major.Name, Major.HeadOfMajor, Major.Description, Major.Objective, Major.MajorLO, Major.Status, Professor.Name AS ProfName FROM Major INNER JOIN Professor ON Major.HeadOfMajor = Professor.ID WHERE (Major.Status = @Status) AND (Major.ProgramID = @ProgramID)" 
                    
                    
                    UpdateCommand="UPDATE [Major] SET [Name] = @Name, [HeadOfMajor] = @HeadOfMajor, [Description] = @Description, [Objective] = @Objective, [MajorLO] = @MajorLO WHERE [ID] = @ID">
                    <DeleteParameters>
                        <asp:Parameter Name="ID" Type="Int32" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ProgramID" Type="Int32" />
                        <asp:Parameter Name="Name" Type="String" />
                        <asp:Parameter Name="HeadOfMajor" Type="Int32" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Objective" Type="String" />
                        <asp:Parameter Name="MajorLO" Type="String" />
                        <asp:Parameter Name="Status" Type="Int32" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
                        <asp:QueryStringParameter Name="ProgramID" QueryStringField="id" Type="Int32" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Name" Type="String" />
                        <asp:Parameter Name="HeadOfMajor" Type="Int32" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Objective" Type="String" />
                        <asp:Parameter Name="MajorLO" Type="String" />
                        <asp:Parameter Name="ID" Type="Int32" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <br />
                <br /><asp:Panel ID="Panel1" runat="server" Visible="False"><table style="width:91%;"><tr><td bgcolor="#00CCFF" style="width: 406px">
                    ProgramID:<asp:DropDownList ID="dl3" runat="server" DataSourceID="q1" 
                                    DataTextField="Name" DataValueField="ID"></asp:DropDownList>&nbsp;<asp:SqlDataSource ID="q1" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                                    SelectCommand="SELECT [ID], [Name] FROM [Program]"></asp:SqlDataSource><br />
                    Name: &nbsp;&nbsp;<asp:TextBox ID="TextBox8" runat="server" Text='<%# Eval("Name") %>' 
                                    Height="22px"></asp:TextBox><br />HeadOfMajor:<asp:DropDownList ID="dl4" runat="server" 
                                    DataSourceID="q2" DataTextField="Name" DataValueField="ID"></asp:DropDownList>
                    &nbsp; <asp:SqlDataSource ID="q2" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                                    SelectCommand="SELECT [ID], [Name] FROM [Professor]"></asp:SqlDataSource></td><td bgcolor="#66FFFF">
                        Description: <asp:TextBox ID="TextBox9" runat="server" Text='<%# Eval("Description") %>'></asp:TextBox><br />
                        Objective:<asp:TextBox ID="TextBox10" runat="server" 
                                    Text='<%# Eval("Objective") %>'></asp:TextBox>&nbsp;<br />MajorLO: &nbsp;&nbsp;<asp:TextBox ID="TextBox11" runat="server" Text='<%# Eval("MajorLO") %>'></asp:TextBox><br /></td></tr></table><br /><asp:LinkButton ID="LinkButton9" runat="server" onclick="LinkButton9_Click">Insert</asp:LinkButton>
                    &nbsp;&nbsp;&nbsp; <asp:LinkButton 
                        ID="LinkButton10" runat="server" CommandName="Cancel" 
                        onclick="LinkButton10_Click">Cancel</asp:LinkButton></asp:Panel>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel ID="tabLearningOutcome" runat="server" HeaderText="Learning Outcome">
        <ContentTemplate><asp:GridView ID="GridView2" runat="server" 
                AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" 
                DataSourceID="LOData" ForeColor="#333333" GridLines="None" 
                ShowFooter="True"><AlternatingRowStyle BackColor="White" ForeColor="#284775" /><Columns><asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" /><asp:TemplateField HeaderText="Code" SortExpression="Code"><EditItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Code") %>'> </asp:TextBox></EditItemTemplate><ItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Bind("Code") %>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Description" SortExpression="Description"><EditItemTemplate><asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'> </asp:TextBox></EditItemTemplate><ItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Bind("Description") %>'> </asp:Label></ItemTemplate></asp:TemplateField><asp:BoundField DataField="Status" HeaderText="Status" 
                    SortExpression="Status" Visible="False" /></Columns><EditRowStyle BackColor="#999999" /><FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /><RowStyle 
                BackColor="#F7F6F3" ForeColor="#333333" /><SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /></asp:GridView><asp:SqlDataSource ID="LOData" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                DeleteCommand="UPDATE ProgramOutcome SET Status = 0 WHERE (ID = @ID)" 
                InsertCommand="INSERT INTO [ProgramOutcome] ([Code], [Description], [Status]) VALUES (@Code, @Description, @Status)" 
                SelectCommand="SELECT * FROM [ProgramOutcome] WHERE ([Status] = @Status)" 
                UpdateCommand="UPDATE [ProgramOutcome] SET [Code] = @Code, [Description] = @Description WHERE [ID] = @ID"><SelectParameters><asp:Parameter DefaultValue="1" Name="Status" Type="String" /></SelectParameters><DeleteParameters><asp:Parameter Name="ID" Type="Int32" /></DeleteParameters><UpdateParameters><asp:Parameter Name="Code" Type="String" /><asp:Parameter Name="Description" Type="String" /><asp:Parameter Name="ID" Type="Int32" /></UpdateParameters><InsertParameters><asp:Parameter Name="Code" Type="String" /><asp:Parameter Name="Description" Type="String" /><asp:Parameter Name="Status" Type="String" /></InsertParameters></asp:SqlDataSource>
        </ContentTemplate>
        </cc1:TabPanel>

    </cc1:TabContainer>
        

</asp:Content>
